<!--
 * @Descripttion: 
 * @Author: Silence
 * @Date: 2023-06-05 20:50:40
 * @LastEditors: Silence
 * @LastEditTime: 2023-06-05 22:02:54
-->
<template>
  <div :style="{ height }" class="box">
    <div class="big" :style="{ transform: 'translateX(' + x + 'vw)' }">
      <slot></slot>
    </div>
    <button class="prev" @click="prev">&lt;</button>
    <button class="next" @click="next">&gt;</button>
  </div>
</template>
<script>
export default {
  name: '',
  props: {
    height: {
      type: String,
      default: '400px',
    }
  },
  data () {
    return {
      x: 0
    }
  },
  created () {
    setInterval(() => {
      this.next()
    }, 1000)
  },
  computed: {
  },
  methods: {
    prev () {
      if (this.x == 0) {
        this.x = -400
      }
      this.x += 100
    },
    next () {
      if (this.x == -300) {
        this.x = 100
      }
      this.x -= 100
    }
  }
}
</script>
<style lang='scss'  scoped>
.box {
  position: relative;
  width: 100vw;
  overflow: hidden;
  .big {
    width: 400vw;
    transition: all 0.5s;
  }
  .prev {
    position: absolute;
    top: 50%;
    left: 20px;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.5);
    width: 40px;
    height: 40px;
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
  }
  .next {
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.5);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
  }
}
</style>
